<?php
/**
 * artDialig 
 * http://code.google.com/p/artdialog
 * @author yangdongqi <yangdongqi@hayzone.com>
 * @package lib.widgets.artDialog
 */
class CArtDialog extends CWidget {
	
	public $type = 'dialog';
	public $options = array();
	protected $_skinsPath;
	
	public function getSkinsPath() {
		if(!$this->_skinsPath) {
			$this->_skinsPath = dirname(__FILE__) . '/assets/skins/';
		}
		return $this->_skinsPath;
	}
	
	public function setSkinsPath($path) {
		$this->_skinsPath = Yii::getPathOfAlias($path);
	}
	
	public function run() {
		self::registerAssetFiles($this->skin);
		$cs = Yii::app()->clientScript;
		
		$options = $this->options;
		$params = CJavaScript::encode($options);
		$script = <<<EOD
jQuery.{$this->type}({$params});
EOD;
		
		$cs->registerScript(
			$this->getId(), 
			$script, 
			CClientScript::POS_END
		);
		
	}
	
	public static function registerAssetFiles($skin) {
		$am = Yii::app()->assetManager;
		$cs = Yii::app()->clientScript;
		$baseUrl = $am->publish(dirname(__FILE__).'/assets/', false, -1, true);
		$jsBaseUrl = $baseUrl . '/js/';
		$cs->registerScriptFile($jsBaseUrl.'jquery.artDialog.js');
		$cs->registerScriptFile($jsBaseUrl.'artDialog.plugins.js');
		if((strpos($skin, '.')) !== false) {
			$skinPath = dirname(Yii::getPathOfAlias($skin));
			$skinBaseUrl = $am->publish($skinPath, false, -1, true) . '/';
			$skin = substr($skin, strrpos($skin, '.')+1);
		} else {
			$skinBaseUrl = $baseUrl . '/skins/';
		}
		$cs->registerCssFile(
			$skinBaseUrl . $skin . '.css'
		);
	}
	

}

?>